﻿using MvcApplication.Entity;
using MvcApplication.Interface;
using System.Web.Mvc;

namespace MvcApplication.Controllers
{
    public class CollectionController : Controller
    {
        ICollectionService _collectionService;

        public CollectionController(ICollectionService collectionService)
        {
            _collectionService = collectionService;
        }

        public ActionResult Ui()
        {
            return View();
        }

        public ActionResult Title(CollectionPostParam param)
        {
            var post = _collectionService.TryGetPost(param);
            return Json(new { title = post.Title });
        }

        public ActionResult Content(CollectionPostParam param)
        {
            var post = _collectionService.TryGetPost(param);
            return Json(new { detail = post.Detail });
        }

        public ActionResult PrevContent(CollectionPostParam param)
        {
            var post = _collectionService.TryGetPost(param);
            ViewBag.Detail = post.Detail;
            return View();
        }

        public ActionResult SavePost(CollectionPostParam param)
        {
            param.IsGetDetail = true;
            var id = _collectionService.SaveToPost(param);
            return Json(id);
        }

        public ActionResult Page()
        {
            return View();
        }

        public ActionResult GetUrlList(string url, string el, int total)
        {
            var list = _collectionService.GetUrlList(url, el, total);
            return Json(list);
        }
    }
}
